home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_02_04 / 2n04073a < prev    next >
Text File  |  1990-10-17  |  2KB  |  69 lines

  1. PROGRAM RunEnv;
  2.  
  3. {$M 2000, 500, 6000}    (* Stack and Heap Min, Max *)
  4.     (* If the heap isn't large enough to put the new string,
  5.        it is not added to the environment.  If you do multiple
  6.        changes, the Heap must be twice as big as the environment,
  7.        as PutEnvString allocates a new env. before deleting the old one.
  8.  
  9.        This program will not work if the max heap takes up all
  10.        the available memory, hence the max heap should be kept
  11.        as low as possible (keeping in mind the above paragraph).
  12.     *)
  13.  
  14. Uses DOS, PutEnv;
  15.  
  16. CONST
  17.   ExecMsg = 'DOS shell.  Type EXIT to return to ';
  18.  
  19. PROCEDURE InvokeDOS(command: String);
  20.   (* runs any DOS command. Call with command='' for a new DOS shell *)
  21. VAR
  22.   olddir: DirStr;
  23.   pathname: DirStr;
  24.   commandtail:  String[255];
  25. BEGIN
  26.   GetDir(0, olddir);
  27.  
  28.   pathname := GetEnv('COMSPEC');
  29.   IF command = '' THEN
  30.     commandtail := ''
  31.   ELSE
  32.     commandtail := '/C ' + command;
  33.  
  34.   SwapVectors;
  35.   Exec(pathname, commandtail);
  36.   SwapVectors;
  37.  
  38.   ChDir(olddir);
  39. END; (* InvokeDOS *)
  40.  
  41. VAR
  42.   promptstr : String[255];
  43. BEGIN (* RunEnv *)
  44.   Writeln('Run the program...');
  45.   Writeln('Type "SET" to see the new environment');
  46.  
  47.   promptstr := GetEnv('PROMPT');
  48.   PutEnvString('PROMPT', ExecMsg + 'RunEnv' + '.$_' + promptstr);
  49.   PutEnvString('NEWSET', 'Anything can be added!');
  50.   PutEnvString('ONE', 'One');
  51.   InvokeDOS('');
  52.  
  53.   Writeln;
  54.   Writeln('Newset was removed from the environment.');
  55.   Writeln('Type "SET" to see the new environment');
  56.   PutEnvString('NEWSET', '' (* or deleted *));
  57.   InvokeDOS('');
  58.   FreeEnvString;
  59.  
  60.   Writeln;
  61.   Writeln('Try a new prompt...and delete the path.');
  62.   Writeln('The environment is:');
  63.   PutEnvString('PROMPT', ExecMsg + 'RunEnv again!' + '.$_' + promptstr);
  64.   PutEnvString('PATH', '' (* or deleted *));
  65.   InvokeDOS('SET');
  66.   FreeEnvString;
  67.   Writeln('The program is finished!');
  68. END. (* RunEnv *)
  69.